﻿using Core.Rendering.Enums;
using OpenTK.Mathematics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Core.Rendering
{
    public struct Camera
    {
        public float Fov { get; set; }
        public float Near {  get; set; }
        public float Far {  get; set; }
        public Color4 ClearColor { get; set; }
        public bool IsFrustumGeometryCulling {  get; set; }
        public bool IsFrustumLightCulling {  get; set; }
        public EProjectionMode ProjectionMode { get; set; }
        public Matrix4 ViewMatrix {  get; set; }
        public Matrix4 PerspectiveMatrix {  get; set; }

        public Camera()
        {
            Fov = 45;
            Near = 0.1f;
            Far = 100.0f;   
            ClearColor = Color4.Brown;
            IsFrustumGeometryCulling = true;
            IsFrustumLightCulling = false;
            ProjectionMode = EProjectionMode.Perspective;
        }
        public void UpdateMatrices(Vector3 position,Quaternion rotation,float width,float height)
        {
            Vector3 unitZ = rotation * Vector3.UnitZ;
            ViewMatrix = Matrix4.LookAt(position, position + unitZ, Vector3.UnitY);
            if(ProjectionMode == EProjectionMode.Perspective)
            {
                PerspectiveMatrix = Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(Fov), width / height, Near, Far);
            }
            else
            {
                PerspectiveMatrix = Matrix4.CreateOrthographic(width,height, Near, Far);
            }
        }
    }
}
